﻿//***********************************************************************
// Assembly         : IGolovkine.AoA.Core
// Author           : Ilia
// Created          : 06-11-2011
//
// Last Modified By : Ilia
// Last Modified On : 06-11-2011
// Description      : 
//
// Copyright        : (c) Microsoft. All rights reserved.
//***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using IGolovkine.AoA.BinarySerialization;
using System.Diagnostics;
using System.Globalization;

namespace IGolovkine.AoA.Tcp
{
    [Serializable]
    public class TcpConnectionData : TcpConnectionMessage 
    {
        private readonly byte[] _data;

        public TcpConnectionData(CorrelationId connectionId, byte[] data) : base(connectionId)
        {
            _data = data;
        }
        
        protected TcpConnectionData(ISlimBinaryReader reader) : base(reader) 
        {
            _data = reader.ReadByteArray();
        }

        public byte[] GetData()
        {
            return _data;
        }

        public string StringData
        {
            get { return Encoding.Default.GetString(_data); }
        }

        public override void Serialize(ISlimBinaryWriter writer)
        {
            base.Serialize(writer);
            writer.WriteByteArray(_data);
        }

        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentCulture, "{0}: Length = {1}", this.GetType().Name, _data.Length);
        }
    }
}
